package entity

import (
	"strconv"
	"strings"
	"time"
)

// Task 任务模板表
type Task struct {
	ID              uint      `gorm:"primarykey" json:"-"`
	TaskId          int64     `json:"taskId"`
	TaskName        string    `json:"taskName"`
	Categories      *string   `json:"categories"`
	Urls            string    `json:"urls"`
	TaskDescription *string   `json:"taskDescription"`
	TaskExecTimes   int       `json:"taskExecTimes"`
	CreatedAt       time.Time `json:"-"`
	UpdatedAt       time.Time `json:"updatedAt"`
}

func (t *Task) CategoryList(list []int64) {
	if len(list) == 0 {
		return
	}
	listStr := make([]string, len(list))
	for i := range list {
		listStr[i] = strconv.FormatInt(list[i], 10)
	}
	categories := strings.Join(listStr, ",")
	t.Categories = &categories
}

func (t *Task) UrlList(list []string) {
	listStr := make([]string, len(list))
	for i := range list {
		listStr[i] = list[i]
	}
	urls := strings.Join(listStr, ",")
	t.Urls = urls
}

// TaskExecRecord 任务执行记录表
type TaskExecRecord struct {
	ID        uint `gorm:"primarykey"`
	TaskId    int64
	ExecId    int
	CreatedAt time.Time
}
